import { CurrencyAPI } from '../index'
import { get, post } from '@/utils/request'

export interface CurrencyStats {
  totalSupply: number
  supplyGrowth: number
  dailyVolume: number
  volumeChange: number
  exchangeRate: number
  mintAuthority: string
}

export interface Transaction {
  id: string
  type: 'mint' | 'transfer' | 'burn'
  amount: number
  from: string
  to: string
  time: string
  status: 'success' | 'pending' | 'failed'
  memo?: string
}

export interface TransactionParams {
  page?: number
  pageSize?: number
  type?: string
  status?: string
  startTime?: string
  endTime?: string
}

export interface MintParams {
  amount: number
  receiver: string
  memo?: string
}

export interface TransferParams {
  amount: number
  from: string
  to: string
  memo?: string
}

export interface BurnParams {
  amount: number
  from: string
  memo?: string
}

export interface ExchangeRate {
  time: string
  rate: number
}

export const CurrencyService = {
  async getStats(): Promise<CurrencyStats> {
    return get<CurrencyStats>(CurrencyAPI.stats)
  },

  async getTransactions(params: TransactionParams): Promise<{
    total: number
    items: Transaction[]
  }> {
    return get(CurrencyAPI.transactions, params)
  },

  async mint(params: MintParams): Promise<Transaction> {
    return post<Transaction>(CurrencyAPI.mint, params)
  },

  async transfer(params: TransferParams): Promise<Transaction> {
    return post<Transaction>(CurrencyAPI.transfer, params)
  },

  async burn(params: BurnParams): Promise<Transaction> {
    return post<Transaction>(CurrencyAPI.burn, params)
  },

  async getExchangeRates(days: number = 7): Promise<ExchangeRate[]> {
    return get(CurrencyAPI.exchangeRates, { days })
  },
}
